package org.dei.perla.aggregates;

import java.util.Random;

import org.dei.perla.parser.expressions.ConstantCastException;
import org.dei.perla.parser.expressions.ConstantFloat;
import org.dei.perla.parser.expressions.ConstantID;
import org.dei.perla.parser.expressions.ConstantInteger;
import org.dei.perla.parser.expressions.ConstantTimestamp;
import org.dei.perla.sys.query.llqruntime.datastructures.Buffer;
import org.dei.perla.sys.query.llqruntime.datastructures.QueryRecordStructure;
import org.dei.perla.sys.query.llqruntime.datastructures.Record;

public class ThreadReadBuffer implements Runnable {
	private Buffer pBuffer;
	public ThreadReadBuffer(Buffer pBuffer) {
		this.pBuffer = pBuffer;
	}
	public  void run() {
		Random random = new Random();
		int bLength = 0; 
		
		do {
			try {
				ConstantFloat[] sample = StreamVariance.sampleArray(pBuffer, "TEMP");
				bLength = sample.length;
				ConstantFloat variance = StatisticSample.variance(sample);
				System.err.println(variance);
			} catch (ConstantCastException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			try {
                Thread.sleep(random.nextInt(500));
            } catch (InterruptedException e) {}
		}while (bLength<5);
	}
}
